﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XW.Core
{
	/// <summary>
	/// 解决Long 前端 丢失精度问题
	/// </summary>
	public class LongJsonConverter:JsonConverter
	{
		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			JToken jt = JValue.ReadFrom(reader);

			return jt.Value<long>();
		}

		public override bool CanConvert(Type objectType)
		{
			return typeof(long).Equals(objectType);
		}

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			serializer.Serialize(writer, value.ToString());
		}
	}
}
